/*
 * @LastEditors: w
 */
var path = require('path');
var webpack = require('webpack');
var FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
var TerserPlugin = require('terser-webpack-plugin');
var time=new Date()
var {version}=require('./version/version')
module.exports =async function (){
    let myVersion=await version()

    return {
        mode: 'development',
        entry: {
            ani:'./src/root/ani.js',
            'ani.router':'./src/ani_router/ani.router.miniprogram.js',
            'ani.store':'./src/ani_store/ani.store.js',
            'ani.store.RD': './src/ani_store/ani.store.RD.js',
        },
        output: {
            path: path.resolve(__dirname, './examples'),
            publicPath: '/examples/',
            filename: '[name].min.js',
            libraryTarget: 'commonjs2',
        },
        optimization: {
            minimize: true,
            minimizer: [
                new TerserPlugin({
                    extractComments: false,//不将注释提取到单独的文件中
                }),
            ],
        },
        // output: {
        //     path: path.resolve(__dirname, './examples'),
        //     publicPath: '/examples/',
        //     filename: 'ani.min.js',
        //     libraryTarget: 'commonjs2',
        // },
        plugins: [
            new webpack.BannerPlugin(`当前版本：${myVersion},构建时间：${time}`),
            // 编译控制台文字
            new FriendlyErrorsWebpackPlugin({
                compilationSuccessInfo: {
                    notes: ['版本名称：dev,当前版本号：'+myVersion,time],
                    messages: ['编译进行中，稍安勿躁.......'],

                },
                // clearConsole: true,
            }),
            new webpack.DefinePlugin({
                'VERSION': JSON.stringify(myVersion)
            }),
        ],
        target: "node",

        devtool: 'source-map',
        module: {
            rules: [
                {
                    test: /\.js$/,
                    loader: 'babel-loader',
                    exclude: /node_modules/
                }
            ]
        },
    }
};
